/**
 * 2015-12-20
 * TeacherController.java
 * author:sherlochao
 */
package com.sherlochao.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.sherlochao.beans.StudentBean;
import com.sherlochao.beans.TeacherBean;
import com.sherlochao.model.Course;
import com.sherlochao.model.Student;
import com.sherlochao.model.StudyCourse;
import com.sherlochao.model.Teacher;
import com.sherlochao.service.StudentService;
import com.sherlochao.service.TeacherService;

/**
 * @author yinchao
 *
 */
@Controller
@RequestMapping("/teacher")
public class TeacherController {
	
	@Resource
	private TeacherService teacherService;
	
	@ResponseBody
	@RequestMapping(value="/getTeacher", method = RequestMethod.POST)
	public String getStudent(String teacherId){
		TeacherBean teacherBean = new TeacherBean();
		Teacher teacher = teacherService.get(teacherId);
		teacherBean.setTeacherId(teacher.getTeacherId());
		teacherBean.setTeacherName(teacher.getTeacherName());
		teacherBean.setTeacherBirthday(teacher.getTeacherBirthdate());
		List<Course> courses = teacherService.listCourseByTeacherId(teacherId);
		teacherBean.setCourses(courses);
		List<Integer> integers = teacherService.listStudentByTeacherId(teacherId);
		teacherBean.setStudents(integers);
		String json = JSON.toJSONString(teacherBean);
		return json;
	}

}
